package com.jidu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jidu.common.utils.poi.ExcelUtil;
import com.jidu.domain.CourseStudentRel;
import com.jidu.service.ICourseStudentRelService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jidu.common.annotation.Log;
import com.jidu.common.core.controller.BaseController;
import com.jidu.common.core.domain.AjaxResult;
import com.jidu.common.enums.BusinessType;
import com.jidu.common.core.page.TableDataInfo;

/**
 * 学生课程关系Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@Slf4j
@Api(tags = "学生课程关系 controller")
@RestController
@RequestMapping("/system/rel")
public class CourseStudentRelController extends BaseController
{
    @Autowired
    private ICourseStudentRelService courseStudentRelService;

    /**
     * 查询学生课程关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:rel:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseStudentRel courseStudentRel)
    {
        startPage();
        List<CourseStudentRel> list = courseStudentRelService.selectCourseStudentRelList(courseStudentRel);
        return getDataTable(list);
    }

    /**
     * 导出学生课程关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:rel:export')")
    @Log(title = "学生课程关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseStudentRel courseStudentRel)
    {
        List<CourseStudentRel> list = courseStudentRelService.selectCourseStudentRelList(courseStudentRel);
        ExcelUtil<CourseStudentRel> util = new ExcelUtil<CourseStudentRel>(CourseStudentRel.class);
        util.exportExcel(response, list, "学生课程关系数据");
    }

    /**
     * 获取学生课程关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rel:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseStudentRelService.selectCourseStudentRelById(id));
    }

    /**
     * 新增学生课程关系
     */
    @PreAuthorize("@ss.hasPermi('system:rel:add')")
    @Log(title = "学生课程关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseStudentRel courseStudentRel)
    {
        return toAjax(courseStudentRelService.insertCourseStudentRel(courseStudentRel));
    }

    /**
     * 修改学生课程关系
     */
    @PreAuthorize("@ss.hasPermi('system:rel:edit')")
    @Log(title = "学生课程关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseStudentRel courseStudentRel)
    {
        return toAjax(courseStudentRelService.updateCourseStudentRel(courseStudentRel));
    }

    /**
     * 删除学生课程关系
     */
    @PreAuthorize("@ss.hasPermi('system:rel:remove')")
    @Log(title = "学生课程关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseStudentRelService.deleteCourseStudentRelByIds(ids));
    }
}
